#include "stdafx.h"
#include "Thread.h"

using namespace System;
using namespace Parallel;

DWORD WINAPI MyThreadFunction( LPVOID lpParam )
{
	Thread* This = reinterpret_cast<Thread*>(lpParam);
	This->run();
	
	return 0;
}

Thread::Thread(void)
:m_threadHandle(NULL)
{
}

Thread::~Thread(void)
{
	if (m_threadHandle != NULL)
	{
		wait();
	}
}

void Thread::start(void)
{	
        m_threadHandle = CreateThread( 
            NULL,                   
            0,                      
            MyThreadFunction,       
            (LPVOID)this,          
            0,                      
            NULL); 
}

void Thread::wait(void)
{
	WaitForSingleObject(m_threadHandle, INFINITE);
}

